<template>
  <view class="uni-padding-wrap">
    <text>onLoad 接收到参数</text>
    <text>data: {{ data }}</text>
    <button @tap="navigateBackWithDelta2" class="uni-btn">
      回退到上上层页面
    </button>
    <button @tap="back" class="uni-btn">back</button>
    <button @click="navigateToNewPage2" class="uni-btn">navigateTo newPage2</button>
  </view>
</template>

<script>
import { state } from '@/store/index'

export default {
  data() {
    return {
      data: '',
    }
  },
  onLoad(options) {
    if (options.data) {
      this.data = options.data
    }
  },
  methods: {
    // 自动化测试
    getLifeCycleNum() {
      return state.lifeCycleNum
    },
    navigateBackWithDelta2() {
      uni.navigateBack({
        delta: 2,
        success() {
          console.log('回退上上层页面成功')
        },
        fail(error) {
          console.warn(`回退上上层页面失败: ${error.errMsg}`)
        },
      })
    },
    navigateToOnLoadWithType(type) {
      uni.navigateTo({
        url: `/pages/navigator/new-page/onLoad?type=${type}`,
      })
    },
    back(){
      uni.navigateBack()
    },
    navigateToNewPage2(){
      uni.navigateTo({
       url: '/pages/navigator/new-page/new-page-2' 
      })
    }
  },
}
</script>
